<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../layui/layui.js"></script>
    <script src="../js/jquery-1.8.0.min.js"></script>
    <script src="/js/ajax.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/shousuokuan.css">
</head>

<body>

    <div class="layuimini-container">
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px">

                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">商品名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="GoodsName" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <label class="layui-form-label">进货日期</label>
                            <div class="layui-input-inline">
                                <input type="text" name="startDate" id="startDate" placeholder="起始日期"
                                    autocomplete="off" class="layui-input">
                            </div>

                            <div class="layui-input-inline">
                                <input type="text" name="endDate" id="endDate" placeholder="最后日期"
                                    autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                        
                        

                    </form>

                </div>
            </fieldset>
        </div>
    </div>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn" lay-submit lay-filter="export">导出Excel</button>
        </div>
    </script>
    <table id="demo" lay-filter="test"></table>
    <script src="../js/host.js"></script>
    <script>

        layui.use(["table", 'form', 'laydate'], function () {
            var table = layui.table;
            var form = layui.form;
            var laydate = layui.laydate;
            table.render({
                elem: '#demo'
                , url: host + '/getSaleInventory' //数据接口
                , page: true //开启分页,
                , headers: {
                    "token": localStorage.getItem("token")
                }
                , toolbar: '#toolbarDemo'
                , loading: true
                , cols: [[ //表头
                    { type: 'numbers', title: '序号' }
                    , { field: 'id', title: 'ID', sort: true, hide: true }
                    , { field: 'commodityName', title: '商品名称' }
                    , { field: 'get_date', title: '进货日期' }
                    , { field: 'end_date', title: '最后销售日期' }
                    , { field: 'get_num', title: '进货数量' }
                    , { field: 'sale_num', title: '销售数量' }
                    , { field: 'inventory_num', title: '库存数量' }
                    , { field: 'get_totalPrice', title: '进货总金额' }
                    , { field: 'sale_totalPrice', title: '已销售金额' }
                ]]
            });

            form.on('submit(formDemo)', function (data) {
                //当前容器的全部表单字段，名值对形式：{name: value}】
                table.reload('demo', {
                    where: data.field
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    } //设定异步数据接口的额外参数
                    //,height: 300
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });

            form.on('submit(export)', function (data) {
                //当前容器的全部表单字段，名值对形式：{name: value}】
                window.open(host + '/InventoryExport?' + $("#form").serialize());
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
            //日期
            laydate.render({
                elem: '#startDate'
            });
            laydate.render({
                elem: '#endDate'
            });
        })
    </script>
</body>

</html>